import store from '@/store'

function checkPermission(el, binding) {
  const { value } = binding
  
  if(!value){
    return
  }
  
  let auth = location.hash.replace('#', '').split('?')[0]+"{"+value+"}"
  
  if(store.state.permission.btnAuth.indexOf(auth) === -1){
    el.parentNode && el.parentNode.removeChild(el)
  }
}

export default {
  inserted(el, binding) {
    checkPermission(el, binding)
  },
  update(el, binding) {
    checkPermission(el, binding)
  }
}
